<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改用户')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form class="form-horizontal" id="form-prjgroup-edit" th:object="${prjgroup}">
        <input name="prjgroupId" type="hidden" th:field="*{prjgroupId}"/>
        <input name="deptId" type="hidden" th:field="*{deptId}" id="treeId"/>
<!--        <input name="leader" type="hidden" th:field="*{leader}"/>-->
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-11">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">项目组名称：</label>
                    <div class="col-sm-8">
                        <input name="prjgroupName" placeholder="项目组名称" class="form-control" type="text" maxlength="30"
                               th:field="*{prjgroupName}" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-11">
                <div class="form-group">
                    <label class="col-sm-4 control-label">归属部门：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()"
                                   id="treeName" th:field="*{deptName}">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-11">
                <div class="form-group">
                    <label class="col-sm-4 control-label">编号：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="code" placeholder="请输入项目编号" class="form-control" type="text" maxlength="11"
                                   th:field="*{code}">

                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-11">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">项目组负责人：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input name="leader" placeholder="请输入项目组负责人" class="form-control" type="text"
                                       th:field="*{leader}">

                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-11">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">项目组介绍：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input name="remark" class="form-control" type="text" maxlength="50"
                                       placeholder="请输入项目组介绍" th:field="*{remark}">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + "system/prjgroup";

    $("#form-prjgroup-edit").validate({
        onkeyup: false,
        rules: {
            email: {
                email: true,
                remote: {
                    url: prefix + "/checkEmailUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "userId": function () {
                            return $("#userId").val();
                        },
                        "email": function () {
                            return $.common.trim($("#email").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            phonenumber: {
                isPhone: true,
                remote: {
                    url: prefix + "/checkPhoneUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "userId": function () {
                            return $("#userId").val();
                        },
                        "phonenumber": function () {
                            return $.common.trim($("#phonenumber").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "email": {
                remote: "Email已经存在"
            },
            "phonenumber": {
                remote: "手机号码已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-prjgroup-edit").serializeArray();

            $.operate.save(prefix + "/edit", data);
        }
    }

    /* 用户管理-修改-选择部门树 */
    function selectDeptTree() {
        var deptId = $.common.isEmpty($("#treeId").val()) ? "1" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }

    $(function () {
        $('#post').select2({
            placeholder: "请选择岗位",
            allowClear: true
        });
    })
</script>
</body>
</html>